<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>test</title>
    <base href="/">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="pragma" content="no-cache">  
    <meta http-equiv="cache-control" content="no-cache">  
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="../dist/arktaoStorage.js"></script>
</head>

<body>
    <div id="container">
        <p>1.上传文件（5MB以下直传,5MB以上自动分片,内置断点续传）</p>
        <input type="file" id="test1">
        <p>2.上传文件并转码（现支持视频转m3u8）</p>
        <input type="file" id="test2">
    </div>
    <script type="module">
        const storage = {
            ApiUrl: "http://localhost:9998/",//必须
            StorageUrl: "http://localhost:9999/"//必须
        }
        document.getElementById("test1").addEventListener("change", (e) => {
            let file = e.target.files[0]
            const observable = arktaoStorage.upload('test', file, file.name, storage)
            observable.subscribe({
                error(err) {
                    console.error(err)
                },
                next(ne) {
                    console.log(ne)
                },
                complete(e) {
                    console.log(e)
                }
            })
        })
        document.getElementById("test2").addEventListener("change", (e) => {
            let file = e.target.files[0]
            const observable = arktaoStorage.upload('test', file, file.name, storage)
            observable.subscribe({
                error(err) {
                    console.error(err)
                },
                next(ne) {
                    console.log(ne)
                },
                complete(e) {
                    trans()
                }
            })
            function trans() {
                const observable = arktaoStorage.trans('test', file.name, storage, {
                    type: 'hls'
                })
                observable.subscribe({
                    error(err) {
                        console.error(err)
                    },
                    next(ne) {
                        console.log(ne)
                    },
                    complete(e) {
                        console.log("转码完成")
                        console.log(e)
                    }
                })
            }
        })
    </script>
</body>

</html>